#ifndef GRPCCLIENTPROXYINSERVER_H
#define GRPCCLIENTPROXYINSERVER_H

#include <queue>

#include <grpc/grpc.h>
#include <grpcpp/security/server_credentials.h>
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
#include <grpcpp/server_context.h>

#include "grpcevent.grpc.pb.h"

using grpc::CallbackServerContext;
using grpc::Server;
using grpc::ServerBuilder;
using grpc::Status;
using Evol::Common::Grpc::Server::GrpcEvent;
using Evol::Common::Grpc::Server::GrpcEventMessage;

/***************************************************************
*  @Copyright:  Copyright (c) 2024 LK. All rights reserved.
*  @FileName:   grpcclientproxyinserver.h
*  @Brief:      连接服务的客户端 代理
*  @Author:     HXJ
*  @Date:       2024-08-17
****************************************************************/

class GrpcEventServerService;
class GrpcClientProxyInService : public grpc::ServerWriteReactor<GrpcEventMessage>
{
public:
    GrpcClientProxyInService(std::string name, GrpcEventServerService* parent);

    //发送消息
    void SendEvent(const std::string& jsonText);

private:
    //流处理完成，或者流异常后主动完成
    void OnDone() override;

    //写入一次完成
    void OnWriteDone(bool ok) override;

    //发送数据
    void WriteOneData();
private:
    std::string m_name;
    GrpcEventServerService* m_parent;

    std::mutex m_mutex;
    bool m_canWrite = true;
    std::queue<GrpcEventMessage> m_dataQueue;
};


#endif // GRPCCLIENTPROXYINSERVER_H
